package com.lhkj.ct.admin.modules.psychology.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.modules.psychology.model.entity.TblScaleGroupReport;
import com.lhkj.ct.meta.modules.psychology.model.vo.GroupReportVo;
import com.lhkj.ct.meta.modules.psychology.service.GroupReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 *      团体报告
 * </p>
 *
 * @author job
 * @since 2023/10/20
 */
@RestController
@RequestMapping("api/plat/psychology/group/report")
@Api(tags = {"2.4团体报告"})
@Validated
public class GroupReportController {


    @Resource
    private GroupReportService groupReportService;

    @GetMapping(value = "list")
    @ApiOperation(value = "列表查询")
//    //@RequiresPermissions(value = {"XLCP:XLCY:TTBG:LIST", "XLCP:XLCY:YBFX:MAIN"}, logical = Logical.OR)
    public ActionResult<IPage<TblScaleGroupReport>> list(TblScaleGroupReport entity, PageQuery pageQuery) {
        return ActionResult.success(groupReportService.selectPages(entity, pageQuery));
    }

    @PostMapping(value = "insert")
    @ApiOperation(value = "新增")
    @Log(title = "团体报告", actionType = ActionType.INSERT)
//    //@RequiresPermissions(value = "XLCY:TTBG:ADD")
    public ActionResult<Void> add(@Validated @RequestBody TblScaleGroupReport entity) {
        groupReportService.save(entity);
        return ActionResult.success();
    }

    @GetMapping(value = "{gId}/get")
    @ApiOperation(value = "查看报告")
//    //@RequiresPermissions(value = {"XLCP:XLCY:TTBG:LIST", "XLCP:XLCY:YBFX:MAIN"}, logical = Logical.OR)
    public ActionResult<GroupReportVo> get(@PathVariable String gId) {
        return ActionResult.success(groupReportService.selectGroupRepInfo(gId));
    }

//    @PostMapping(value = "{rId}/exportWord")
//    @ApiOperation(value = "导出word")
//    @Log(title = "团体报告", actionType = ActionType.EXPORT)
////    //@RequiresPermissions(value = "XLCY:TTBG:EXPORT")
//    public void exportWordReport(@PathVariable String rId) {
//        groupReportService.exportWord(rId);
//    }

    @PutMapping(value = "{rId}/exportPdf")
    @ApiOperation(value = "导出pdf")
    @Log(title = "团体报告", actionType = ActionType.EXPORT, isSaveResponseData = false)
//    //@RequiresPermissions(value = "XLCY:TTBG:EXPORT")
    public void exportPdf(@PathVariable String rId) {
        groupReportService.exportPdf(rId);
    }

    @DeleteMapping(value = "delete")
    @ApiOperation(value = "删除")
    @Log(title = "团体报告", actionType = ActionType.DELETE)
    public ActionResult<Void> delete(@NotEmpty(message = "请选择要删除的报告") @RequestBody List<String> ids) {
        int count = groupReportService.removeByIds(ids);
        return ActionResult.success(String.format("操作成功，共删除[%d]个报告", count));
    }
}
